package com.lzyx.request;

import io.netty.channel.ChannelFuture;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 提供串行队列的命令channel支持
 * @author richa
 */
public abstract class AbstractQueueCommandChannel implements ICommandChannel{

    protected Queue<ICommandRequest> commandQueue = new LinkedBlockingQueue<>(5);

    protected boolean tryProcessCommand(ICommandRequest request){
        if(this.commandQueue.peek() == null){
            this.send(request);
            return true;
        }
        return commandQueue.offer(request);
    }



    protected abstract ChannelFuture send(ICommandRequest request);
}
